package org.mobile.model.util;

import java.util.Map;

/**
 * 界面相关处理通用函数
 * @author shin
 */
public class ViewUtils {
    /**
     * 添加额外的js到map中
     * @param path
     *            前缀路径
     * @param map
     * @param files
     */
    public static void appendExtraJS(String path, Map<String, Object> map,
            String... files) {
        if(files == null || files.length < 1)
            return;
        Object temp = map.get("extraJavaScript");
        StringBuilder sb = new StringBuilder();
        sb.append(temp == null || !(temp instanceof String) ? "" : temp);
        for(String file : files) {
            sb.append("<script type='text/javascript' src=\"").append(path)
                    .append("/").append(file).append("\"></script>");
        }
        map.put("extraJavaScript", sb.toString());
    }

    public static void appendExtraJS(Map<String, Object> map, String... files) {
        appendExtraJS("/js", map, files);
    }

    /**
     * 添加额外的css到map中
     * @param path
     *            前缀路径
     * @param map
     * @param files
     */
    public static void appendExtraCSS(String path, Map<String, Object> map,
            String... files) {
        if(files == null || files.length < 1)
            return;
        Object temp = map.get("extraCss");
        StringBuilder sb = new StringBuilder();
        sb.append(temp == null || !(temp instanceof String) ? "" : temp);
        for(String file : files) {
            sb.append("<link href=\"").append(path).append("/").append(file)
                    .append("\" rel=\"stylesheet\" />");
        }
        map.put("extraCss", sb.toString());
    }

    public static void appendExtraCSS(Map<String, Object> map, String... files) {
        appendExtraCSS("/css", map, files);
    }
}
